package com.zoo.buyor.user.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zoo.buyor.user.domain.entity.User;
import com.zoo.buyor.user.mapper.UserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author <a href="https://gitee.com/ArZoo">阿祖</a>
 * @since 2024-01-22
 */
@Service
public class UserDao extends ServiceImpl<UserMapper, User>  {

    public User getByOpenId(String openId) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getOpenId, openId);
        return getOne(queryWrapper);
    }

    public User getByName(String newName) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getName, newName);
        return getOne(queryWrapper);
    }

    public void modifyName(Long uid, String name) {
        User user = new User();
        user.setId(uid);
        user.setName(name);
        updateById(user);
    }
}
